<?php

$php_self = addslashes(htmlspecialchars($_SERVER['PHP_SELF'] ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_NAME']));
$timestamp = time();

function DoPage($sql, $pagesize, &$curpage, $href_prefix) {
	$result = mysql_query($sql);
	$rs = mysql_fetch_array($result);
	$total = $rs[0];
	$pagenum = ceil($total/$pagesize);
	if(!isset($_GET['page']))
	{
		$curpage = 1;
	}
	else if(is_numeric($_GET['page']))
	{
		$curpage = $_GET['page'];
	}
	if($curpage > ceil($total/$pagesize)) $curpage = ceil($total/$pagesize);
	if($curpage < 1) $curpage=1;
	
	echo "\t<div class='selectpage' style='text-align:left; margin:5px;'>".$curpage."/".$pagenum."页&nbsp;&nbsp;";
	for($i=1;$i<=$pagenum;$i++)
	{
		if($i == $curpage){echo $i."&nbsp;";}
		else echo "<a href='".$href_prefix."&page=".$i."'>".$i."&nbsp;</a>";
	}
	echo "</div>\n";
}

//转义特殊字符
function my_addslashes($str) {
	if(get_magic_quotes_gpc())
		return $str;
	else
		return addslashes($str);
}

// Get IP of the clientside.
function GetIp() {
	if (isset($_SERVER)) {
		if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
			$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
		} elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
			$ip = $_SERVER['HTTP_CLIENT_IP'];
		} else {
			$ip = $_SERVER['REMOTE_ADDR'];
		}
	} else {
		if (getenv("HTTP_X_FORWARDED_FOR")) {
			$ip = getenv( "HTTP_X_FORWARDED_FOR");
		} elseif (getenv("HTTP_CLIENT_IP")) {
			$ip = getenv("HTTP_CLIENT_IP");
		} else {
			$ip = getenv("REMOTE_ADDR");
		}
	}
	return $ip;
}

?>